|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.github.droidfu.imageloader.ImageLoader
public class ImageLoader
Realizes an background image loader backed by a two-level FIFO cache. If the image to be loaded is present in the cache, it is set immediately on the given view. Otherwise, a thread from a thread pool will be used to download the image in the background and set the image on the view as soon as it completes.
Field Summary | |
---|---|
static String |
BITMAP_EXTRA
|
protected static int |
DEFAULT_POOL_SIZE
|
protected static int |
DEFAULT_RETRY_HANDLER_SLEEP_TIME
|
protected static ThreadPoolExecutor |
executor
|
protected static long |
expirationInMinutes
|
static int |
HANDLER_MESSAGE_ID
|
static String |
IMAGE_URL_EXTRA
|
protected static ImageCache |
imageCache
|
protected static int |
numRetries
|
Constructor Summary | |
---|---|
protected |
ImageLoader(String imageUrl,
ImageLoaderHandler handler)
|
Method Summary | |
---|---|
static void |
clearCache()
Clears the 1st-level cache (in-memory cache). |
protected android.graphics.Bitmap |
downloadImage()
|
static ImageCache |
getImageCache()
Returns the image cache backing this image loader. |
static void |
initialize(android.content.Context context)
This method must be called before any other method is invoked on this class. |
static void |
initialize(android.content.Context context,
long expirationInMinutes)
|
void |
notifyImageLoaded(String url,
android.graphics.Bitmap bitmap)
|
protected byte[] |
retrieveImageData()
|
void |
run()
The job method run on a worker thread. |
static void |
setMaxDownloadAttempts(int numAttempts)
|
static void |
setThreadPoolSize(int numThreads)
|
static void |
start(String imageUrl,
ImageLoaderHandler handler)
Triggers the image loader for the given image and handler. |
static void |
start(String imageUrl,
ImageLoaderHandler handler,
android.graphics.drawable.Drawable dummyDrawable,
android.graphics.drawable.Drawable errorDrawable)
Triggers the image loader for the given image and handler. |
static void |
start(String imageUrl,
android.widget.ImageView imageView)
Triggers the image loader for the given image and view. |
static void |
start(String imageUrl,
android.widget.ImageView imageView,
android.graphics.drawable.Drawable dummyDrawable,
android.graphics.drawable.Drawable errorDrawable)
Triggers the image loader for the given image and view and sets a dummy image while waiting for the download to finish. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int HANDLER_MESSAGE_ID
public static final String BITMAP_EXTRA
public static final String IMAGE_URL_EXTRA
protected static final int DEFAULT_POOL_SIZE
protected static final int DEFAULT_RETRY_HANDLER_SLEEP_TIME
protected static ThreadPoolExecutor executor
protected static ImageCache imageCache
protected static int numRetries
protected static long expirationInMinutes
Constructor Detail |
---|
protected ImageLoader(String imageUrl, ImageLoaderHandler handler)
Method Detail |
---|
public static void setThreadPoolSize(int numThreads)
numThreads
- the maximum number of threads that will be started to download images in parallelpublic static void setMaxDownloadAttempts(int numAttempts)
numAttempts
- how often the image loader should retry the image download if network connection
failspublic static void initialize(android.content.Context context)
WebImageView
or WebGalleryAdapter
, then
there is no need to call this method, since those classes will already do that for you. This
method is idempotent. You may call it multiple times without any side effects.
context
- the current contextpublic static void initialize(android.content.Context context, long expirationInMinutes)
public static void start(String imageUrl, android.widget.ImageView imageView)
imageUrl
- the URL of the image to downloadimageView
- the ImageView which should be updated with the new imagepublic static void start(String imageUrl, android.widget.ImageView imageView, android.graphics.drawable.Drawable dummyDrawable, android.graphics.drawable.Drawable errorDrawable)
imageUrl
- the URL of the image to downloadimageView
- the ImageView which should be updated with the new imagedummyDrawable
- the Drawable set to the ImageView while waiting for the image to be downloadederrorDrawable
- the Drawable set to the ImageView if a download error occurspublic static void start(String imageUrl, ImageLoaderHandler handler)
ImageLoaderHandler
and handle the loaded image yourself (e.g. cache it for later
use).
imageUrl
- the URL of the image to downloadhandler
- the handler which is used to handle the downloaded imagepublic static void start(String imageUrl, ImageLoaderHandler handler, android.graphics.drawable.Drawable dummyDrawable, android.graphics.drawable.Drawable errorDrawable)
ImageLoaderHandler
and handle the loaded image yourself (e.g. cache it for later
use).
imageUrl
- the URL of the image to downloadhandler
- the handler which is used to handle the downloaded imagedummyDrawable
- the Drawable set to the ImageView while waiting for the image to be downloadederrorDrawable
- the Drawable set to the ImageView if a download error occurspublic static void clearCache()
Application.onLowMemory()
.
public static ImageCache getImageCache()
ImageCache
public void run()
run
in interface Runnable
protected android.graphics.Bitmap downloadImage()
protected byte[] retrieveImageData() throws IOException
IOException
public void notifyImageLoaded(String url, android.graphics.Bitmap bitmap)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |